package com.example.myapplication.adapter;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication.R;

import java.util.List;

public class DynastyAdapter extends RecyclerView.Adapter<DynastyAdapter.ViewHolder> {
    List<String> list ;
    Context context;
    Activity activity;
    FragmentManager fragmentManager;
    OnItemClickListener onItemClickListener;

    public DynastyAdapter(List<String> list, FragmentManager supportFragmentManager, Context context, FragmentActivity activity, OnItemClickListener onItemClickListener) {
        this.list = list;
        this.fragmentManager = fragmentManager;
        this.context = context;
        this.activity = activity;
        this.onItemClickListener = onItemClickListener;
    }

    @NonNull
    @Override
    public DynastyAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext() , R.layout.dynasty_item , null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull DynastyAdapter.ViewHolder holder, int position) {
        holder.textView1.setText(list.get(position));
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView textView1;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            textView1 = itemView.findViewById(R.id.dynasty_textView1);
            textView1.setOnClickListener(new View.OnClickListener() {
                @SuppressLint("ResourceType")
                @Override
                public void onClick(View v) {
                    onItemClickListener.onClick(getAdapterPosition());
                }
            });
        }
   }
   public interface OnItemClickListener{
        void onClick(int position);
   }
}
